﻿using System;
using XEvolve.Core.Events;
using XEvolve.Core.Runtime;
using XEvolve.Core.Runtime.Attributes;
using XEvolve.Core.Runtime.Internal;

namespace XEvolve.Core
{
    [PluginId("xevolve.core")]
    public class CorePlugin : Plugin
    {
        protected override void Initialize(Platform platform)
        {
            platform.Registry.RegisterExtensionPoint("xevolve.adapterFactories");
            platform.Registry.RegisterExtensionPoint("xevolve.topics");


            platform.RegisterService(typeof(IServiceLocator), platform.ServiceLocator);
            platform.RegisterService<AdapterManager, AdapterManager>();
        }
    }

    public static class CoreExtensionPoints
    {
        public static void RegisterAdapterFactory<FactoryType>(this IExtensionRegistry registry) where FactoryType : IAdapterFactory
        {
            registry.RegisterExtension("xevolve.adapterFactories", typeof(FactoryType));
        }

        public static void RegisterAdapterFactory(this IExtensionRegistry registry, IAdapterFactory factory)
        {
            registry.RegisterExtension("xevolve.adapterFactories", factory);
        }

        public static void RegisterTopic<EventArguments>(this IExtensionRegistry registry, ITopic<EventArguments> topic) where  EventArguments : EventArgs
        {
            registry.RegisterExtension("xevolve.topics", topic);
        }

        public static void RegisterTopic<EventArguments, TopicType>(this IExtensionRegistry registry) where  EventArguments : EventArgs where TopicType : ITopic<EventArguments>
        {
            registry.RegisterExtension("xevolve.topics", typeof(TopicType));
        }
    }
}
